import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/data/entities/application/execute_entity.dart';

///特殊作业-通用方法
class CommonSpecialMethods {
  ///指定类型人员数据是否填写完成
  ///返回参数 true:作业人未填写完善  false：填写完成
  ///[type]0：作业实施人 1：作业负责人 2：监护人 3:编制人 4：司索人 5:指挥人 6：用电人 7：安全交底人 8：接受交底人 9：验收人
  static bool notFilledInByType({required List<ExecuteTicketReceiptListOperatorLists> operatorList, required int type}) {
    //是否包含operatorType为type的实施人员
    bool operatorType = false;
    //信息是否全部填写完成
    bool fillInAll = true;
    for (var item in operatorList) {
      if (item.operatorType == type) {
        operatorType = true;
      }
      if (item.operatorType == type && (item.operatorUserId!.isEmpty || item.operatorUserName!.isEmpty || item.operatorUserSign!.isEmpty)) {
        //有类型为作业人的数据且数据有空
        fillInAll = false;
        break;
      }
    }
    return !fillInAll || !operatorType;
  }

  ///查找人员列表中指定类型并替换
  ///返回参数 true:作业人未填写完善  false：填写完成
  ///[type]0：作业实施人 1：作业负责人 2：监护人 3:编制人 4：司索人 5:指挥人 6：用电人 7：安全交底人 8：接受交底人 9：验收人
  static void replacedElementBYType({
    required List<ExecuteTicketReceiptListOperatorLists> operatorList,
    required ExecuteTicketReceiptListOperatorLists operatorLists,
    required int type,
  }) {
    //是否存在type类型的数据
    bool isExist = false;
    for (var item in operatorList) {
      if (item.operatorType == type) {
        isExist = true;
        break;
      }
    }
    if (isExist) {
      //替换原来的数据
      operatorList.where((e) => e.operatorType == type).forEach((e) => operatorList[operatorList.indexOf(e)] = operatorLists);
    } else {
      //添加
      operatorList.add(operatorLists);
    }
  }

  /// ****************************** 执行作业审批节点判断 ******************************//
  /// 作业申请节点-数据校验
  ///[businessType] 1：动火作业 2：受限空间作业 3：盲板抽堵作业 4：高处作业 5：吊装作业 6：临时用电作业 7：动土作业 8：断路作业
  ///[ticketReceipt] 申请节点数据
  ///[onNext] 下一步执行方法
  static void executeJobApplication({
    required String businessType,
    required ExecuteTicketReceiptList ticketReceipt,
    required Function() onNext,
  }) {
    //判断作业类型
    switch (businessType) {
      //动火作业
      case '1':
        fireJobApplication(ticketReceipt, onNext);
        break;
      //受限空间
      case '2':
        restrictedJobApplication(ticketReceipt, onNext);
        break;
      //盲板抽堵
      case '3':
        blindPlateJobApplication(ticketReceipt, onNext);
        break;
      //高处作业
      case '4':
        heightJobApplication(ticketReceipt, onNext);
        break;
      //吊装作业
      case '5':
        hoistingJobApplication(ticketReceipt, onNext);
        break;
      //临时用电
      case '6':
        electricityJobApplication(ticketReceipt, onNext);
        break;
      //动土作业
      case '7':
        groundJobApplication(ticketReceipt, onNext);
        break;
      //断路作业
      case '8':
        roadJobApplication(ticketReceipt, onNext);
        break;
      default:
        break;
    }
  }

  ///作业申请数据校验-动火作业
  static void fireJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPlace!.isEmpty) {
      AppToast.showWarning('请输入动火地点及动火部位!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workModeConfigs!.isEmpty) {
      AppToast.showWarning('请选择动火方式!');
      return;
    }
    if (ticketReceipt.ticketTypeId!.isEmpty) {
      AppToast.showWarning('请选择动火作业级别!');
      return;
    }
    //特级动火作业时,作业方案为必填
    if (ticketReceipt.ticketTypeId! == '1' && ticketReceipt.workPlan!.isEmpty) {
      AppToast.showWarning('请选择上传作业方案!');
      return;
    }
    if (ticketReceipt.ticketTypeId!.isEmpty) {
      AppToast.showWarning('请选择动火作业级别!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善动火人信息！');
      return;
    }
    if (ticketReceipt.workDepartmentId!.isEmpty) {
      AppToast.showWarning('请选择作业单位!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    // if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
    //   AppToast.showWarning('请填写监护人信息!');
    //   return;
    // }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-受限空间
  static void restrictedJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.confinedSpaceName!.isEmpty) {
      AppToast.showWarning('请输入受限空间名称!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.confinedSpaceMediumName!.isEmpty) {
      AppToast.showWarning('请输入受限空间内原有介质名称!');
      return;
    }
    // if (ticketReceipt.workPlan!.isEmpty) {
    //   AppToast.showWarning('请选择上传作业方案!');
    //   return;
    // }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善作业人信息！');
      return;
    }
    if (ticketReceipt.workDepartmentId!.isEmpty) {
      AppToast.showWarning('请选择作业单位!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-盲板抽堵
  static void blindPlateJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }

    if (ticketReceipt.workOtherDataDTO!.blindPlateType!.isEmpty) {
      AppToast.showWarning('请选择作业类别!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.pipeName!.isEmpty) {
      AppToast.showWarning('请输入设备、管道名称!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.pipeMedium!.isEmpty) {
      AppToast.showWarning('请输入管道介质!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.pipeTemperature!.isEmpty) {
      AppToast.showWarning('请输入管道温度!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.pipePressure!.isEmpty) {
      AppToast.showWarning('请输入管道压力!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.blindPlateMaterial!.isEmpty) {
      AppToast.showWarning('请输入盲板材质!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.blindPlateSpecification!.isEmpty) {
      AppToast.showWarning('请输入盲板规格!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workPiPingDTO!.blindPlateNumber!.isEmpty) {
      AppToast.showWarning('请输入盲板编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.blindPlatePosition!.isEmpty) {
      AppToast.showWarning('请上传盲板位置图及编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.sign!.isEmpty) {
      AppToast.showWarning('请完成编制人签字!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.signTime!.isEmpty) {
      AppToast.showWarning('请选择时间!');
      return;
    }
    // if (ticketReceipt.workPlan!.isEmpty) {
    //   AppToast.showWarning('请选择上传作业方案!');
    //   return;
    // }
    // if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 3)) {
    //   AppToast.showWarning('请填写完善编制人信息！');
    //   return;
    // }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善作业人信息！');
      return;
    }
    if (ticketReceipt.workDepartmentId!.isEmpty) {
      AppToast.showWarning('请选择作业单位!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-高处作业
  static void heightJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.operatorHeight!.isEmpty) {
      AppToast.showWarning('请填写作业高度!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.heightLevel!.isEmpty) {
      AppToast.showWarning('请填写作业级别!');
      return;
    }
    // if (ticketReceipt.workPlan!.isEmpty) {
    //   AppToast.showWarning('请选择上传作业方案!');
    //   return;
    // }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善作业人信息！');
      return;
    }
    if (ticketReceipt.workDepartmentId!.isEmpty) {
      AppToast.showWarning('请选择作业单位!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-吊装作业
  static void hoistingJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }

    if (ticketReceipt.workOtherDataDTO!.otherTicketAddress!.isEmpty) {
      AppToast.showWarning('请选择吊物地点!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.slingName!.isEmpty) {
      AppToast.showWarning('请选择吊具名称!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善作业人信息！');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 4)) {
      AppToast.showWarning('请填写完善司索人信息！');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 5)) {
      AppToast.showWarning('请填写完善指挥人信息！');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.slingWeight!.isEmpty) {
      AppToast.showWarning('请选择吊物质量及作业级别!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-临时用电
  static void electricityJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerAccessDeviceName!.isEmpty) {
      AppToast.showWarning('请输入用电设备名称!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerAccessDevicePower!.isEmpty) {
      AppToast.showWarning('请输入额定功率!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerAccessVoltage!.isEmpty) {
      AppToast.showWarning('请输入工作电压!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerAccessPoint!.isEmpty) {
      AppToast.showWarning('请输入电源接入点!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerAccessPower!.isEmpty) {
      AppToast.showWarning('请输入许可用电功率!');
      return;
    }
    // if (ticketReceipt.workPlan!.isEmpty) {
    //   AppToast.showWarning('请选择上传作业方案!');
    //   return;
    // }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 0)) {
      AppToast.showWarning('请填写完善作业人信息！');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 6)) {
      AppToast.showWarning('请填写完善用电人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-动土作业
  static void groundJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }

    if (ticketReceipt.workOtherDataDTO!.otherTicketAddress!.isEmpty) {
      AppToast.showWarning('请选择作业地点!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workDepth!.isEmpty) {
      AppToast.showWarning('请输入作业深度!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.workArea!.isEmpty) {
      AppToast.showWarning('请输入作业面积!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.simpleMapUrl!.isEmpty) {
      AppToast.showWarning('请上传简图!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.sign!.isEmpty) {
      AppToast.showWarning('请完成签字!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.signTime!.isEmpty) {
      AppToast.showWarning('请选择时间!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写监护人信息!');
      return;
    }
    //判断是否还有下一节点,有就弹出下一节点负责人选择弹窗
    onNext();
  }

  ///作业申请数据校验-断路作业
  static void roadJobApplication(ExecuteTicketReceiptList ticketReceipt, Function() onNext) {
    //输入判断
    if (ticketReceipt.receiptNo!.isEmpty) {
      AppToast.showWarning('请输入作业编号!');
      return;
    }
    // if (ticketReceipt.workOtherDataDTO!.involveList!.isEmpty) {
    //   AppToast.showWarning('请选择涉及相关作业单位!');
    //   return;
    // }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 1)) {
      AppToast.showWarning('请填写完善作业负责人信息!');
      return;
    }
    if (CommonSpecialMethods.notFilledInByType(operatorList: ticketReceipt.operatorLists!, type: 2)) {
      AppToast.showWarning('请填写完善监护人信息!');
      return;
    }
    if (ticketReceipt.workDepartmentId!.isEmpty) {
      AppToast.showWarning('请选择作业单位!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerOffReason!.isEmpty) {
      AppToast.showWarning('请输入断路原因!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerOffRemark!.isEmpty) {
      AppToast.showWarning('请输入断路地段相关说明!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.powerOffMapUrl!.isEmpty) {
      AppToast.showWarning('请上传断路地段示意图!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.sign!.isEmpty) {
      AppToast.showWarning('请完成签字!');
      return;
    }
    if (ticketReceipt.workOtherDataDTO!.signTime!.isEmpty) {
      AppToast.showWarning('请选择时间!');
      return;
    }
    // if (ticketReceipt.workPlan!.isEmpty) {
    //   AppToast.showWarning('请选择上传作业方案!');
    //   return;
    // }

    onNext();
  }

  /// ****************************** 气体分析节点判断 ******************************//
  ///判断气体分析是否填写,信息是否填写完善,返回true为未填写
  ///[ticketGasList]气体分析列表
  ///[businessType] 1：动火作业 2：受限空间 6：临时用电作业
  static bool gasAnalysisNotFilledIn({
    required List<ExecuteTicketGasList> ticketGasList,
    required String businessType,
  }) {
    if (ticketGasList.isEmpty) {
      AppToast.showWarning('请添加气体分析信息！');
      return true;
    }
    for (int i = 0; i < ticketGasList.length; i++) {
      final ExecuteTicketGasList item = ticketGasList[i];
      if (item.sampleDate!.isEmpty) {
        AppToast.showWarning('请选择第${i + 1}项中 取样分析时间！');
        return true;
      }
      if (item.addressName!.isEmpty) {
        AppToast.showWarning('请填写第${i + 1}项中 分析点名称！');
        return true;
      }
      if (item.workGasJsonDTOList!.isEmpty) {
        AppToast.showWarning('请添加${i + 1}项中 检测数据！');
        return true;
      }
      //检测数据
      for (var index = 0; index < item.workGasJsonDTOList!.length; index++) {
        final ExecuteTicketGasListWorkGasJsonDTOList gasItem = item.workGasJsonDTOList![index];
        switch (businessType) {
          // 动火作业--只判断名称和结果是否填写
          case '1':
            if (gasItem.gasName!.isEmpty) {
              AppToast.showWarning('请填写${i + 1}项中 代表性气体！');
              return true;
            }
            if (gasItem.gasResult!.isEmpty) {
              AppToast.showWarning('请填写${i + 1}项中 分析结果！');
              return true;
            }
            break;
          // 受限空间--有毒有害气体、可燃气体判断三项，氧气含量检查分析结果
          case '2':
            if (gasItem.gasTypeName == '有毒有害气体' || gasItem.gasTypeName == '可燃气体') {
              if (gasItem.gasName!.isEmpty) {
                AppToast.showWarning('请填写${i + 1}项中 代表性气体！');
                return true;
              }
              if (gasItem.gasQualified!.isEmpty) {
                AppToast.showWarning('请填写${i + 1}项中 合格标准！');
                return true;
              }
              if (gasItem.gasResult!.isEmpty) {
                AppToast.showWarning('请填写${i + 1}项中 分析结果！');
                return true;
              }
            } else {
              if (gasItem.gasResult!.isEmpty) {
                AppToast.showWarning('请填写${i + 1}项中 分析结果！');
                return true;
              }
            }
          // 临时用电--只判断结果是否填写
          case '6':
            if (gasItem.gasResult!.isEmpty) {
              AppToast.showWarning('请填写${i + 1}项中 分析结果！');
              return true;
            }
            break;
        }
      }
      //签名
      if (item.sampleUserSign!.isEmpty) {
        AppToast.showWarning('请完成${i + 1}项中 分析人签名！');
        return true;
      }
    }
    return false;
  }

  /// ****************************** 安全措施节点判断 ******************************//
  ///判断安全措施是否填写,信息是否填写完善,返回true为未填写
  ///[safetyMeasuresList]安全措施列表
  static bool safetyMeasuresNotFilledIn({required List<ExecuteWorkSafetyMeasuresList> safetyMeasuresList}) {
    if (safetyMeasuresList.isEmpty) {
      AppToast.showWarning('请在后台添加安全措施数据！');
      return true;
    }
    for (int i = 0; i < safetyMeasuresList.length; i++) {
      final ExecuteWorkSafetyMeasuresList item = safetyMeasuresList[i];

      // 如果涉及的情况下,进行编辑判断
      if (item.isInvolve == 1) {
        // 包含'-^'为可以输入编辑的类型
        if (item.safetyMeasures!.contains('-^')) {
          // 查询字符中的'-^'和'+^'之间可以编辑的数据
          final matches = RegExp(r'-\^([^\+]+)?\+\^').allMatches(item.safetyMeasures!);
          for (var value in matches) {
            // 如果有未填写的
            if (value.group(1) == null) {
              AppToast.showWarning('请点击编写第${i + 1}项中 措施数据！');
              return true;
            }
          }
        }
        // 包含'-<'为选择类型
        if (item.safetyMeasures!.contains('-<')) {
          // 没有进行勾选
          if (!item.safetyMeasures!.contains('+~')) {
            AppToast.showWarning('请点击选择第${i + 1}项中 措施数据！');
            return true;
          }
        }
      }

      // 编制人签字
      // if (item.safetyMeasures!.contains('其他安全措施') && item.preparedSign!.isEmpty) {
      //   AppToast.showWarning('请完成第${i + 1}项中 编制人签名！');
      //   return true;
      // }

      // 其他安全措施不进行判断
      if (item.safetyMeasures!.contains('其他安全措施')) {
        return false;
      }

      // 签字
      if (item.userSign!.isEmpty) {
        AppToast.showWarning('请完成第${i + 1}项中 ${item.controlAuthName!}签名！');
        return true;
      }

      //是否涉及 0：未涉及 1：涉及
      //涉及需要拍摄图片
      // if (item.isInvolve == 1 && item.images!.isEmpty) {
      //   AppToast.showWarning('请上传第${i + 1}项中 安全措施图片！');
      //   return true;
      // }
    }
    return false;
  }

  /// ****************************** 安全交底节点判断 ******************************//
  ///判断安全交底是否填写,信息是否填写完善,返回true为未填写
  ///[safetyDisclosureList]安全交底列表
  static bool safetyDisclosureNotFilledIn({required List<ExecuteTicketDiscloseList> safetyDisclosureList}) {
    for (int i = 0; i < safetyDisclosureList.length; i++) {
      final ExecuteTicketDiscloseList item = safetyDisclosureList[i];

      /// 交底类型 0：安全交底人 1：接受交底人 2：监护人
      switch (item.discloseType) {
        //安全交底人
        case 0:
          if (item.discloseUserSign!.isEmpty) {
            AppToast.showWarning('请完成安全交底人签名！');
            return true;
          }
          break;
        //接受交底人
        case 1:
          if (item.discloseUserSign!.isEmpty) {
            AppToast.showWarning('请完成接受交底人签名！');
            return true;
          }
          // if (item.discloseFile!.isEmpty) {
          //   AppToast.showWarning('请完成接受交底文件上传！');
          //   return true;
          // }
          // if (item.discloseVideo!.isEmpty) {
          //   AppToast.showWarning('请完成接受交底记录上传！');
          //   return true;
          // }
          break;
        case 2:
          if (item.discloseUserSign!.isEmpty) {
            AppToast.showWarning('请完成监护人签名！');
            return true;
          }
          // if (item.discloseFile!.isEmpty) {
          //   AppToast.showWarning('请完成监护人附件上传！');
          //   return true;
          // }
          break;
      }
    }
    return false;
  }

  /// ****************************** 作业审批、作业关闭节点判断 ******************************//
  ///判断安全交底是否填写,信息是否填写完善,返回true为未填写
  ///[workCheckList]作业审批列表
  static bool workCheckNotFilledIn({required List<ExecuteWorkCheckList> workCheckList}) {
    for (var item in workCheckList) {
      //签名
      if (item.checkUserSign!.isEmpty) {
        AppToast.showWarning('请完成 ${item.checkProject} 签名！');
        return true;
      }
      //意见
      if (item.checkReason!.isEmpty) {
        if (item.checkProject == '完工验收') {
          item.checkReason = '现场已清理，未留下隐患';
        } else {
          item.checkReason = '同意';
        }
        // AppToast.showWarning('请完成 ${item.checkProject} 审核意见！');
        // return true;
      }
      //时间
      if (item.checkDate!.isEmpty) {
        AppToast.showWarning('请完成 ${item.checkProject} 时间选择！');
        return true;
      }
      //时间
      if (item.checkImage!.isEmpty) {
        AppToast.showWarning('请完成 ${item.checkProject} 拍照认证！');
        return true;
      }
    }
    return false;
  }

  ///饼图值计算
  ///[dividend] 被除数
  ///[divisor] 除数
  ///[decimalPlaces] 小数位数
  static double pieChartValueCalculation({required int dividend, required int divisor, int? decimalPlaces}) {
    if (dividend == 0 || divisor == 0) {
      return 0;
    }
    return double.parse((dividend / divisor * 100).toStringAsFixed(decimalPlaces ?? 2));
  }
}
